'''
    绑定参数
'''
import pymysql
try:
    myconn = pymysql.connect(host='localhost', port=3306, db='shuoGG', user='root', password='ut123456', charset='utf8mb4')
    sql = 'select * from student where sname=%s'    # 这里的%s和string的占位是完全两回事, 这是execute负责解析的
    params = ['小刚']                               # params的参数顺序和%s对应; 列表或元组都行
    cur = myconn.cursor() 
    cur.execute(sql, params)
    result1 = cur.fetchone()                        # 查询第1条, 返回一个元组, cur指针自动指向下一条数据
    print(result1)                                  # ('小刚', 1)              

    cur.close()
    myconn.close()

except Exception as e:
    print(e.message)
